package com.base.service;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.springframework.stereotype.Service;
/**
 * 初始化hbase数据库连接
 * @author Administrator
 *
 */
@Service("hbaseConnService")
public class HbaseConnService {
	private  Connection conn = null;
	public Connection getHbaseConnection (){
		try {
			Configuration conf = HBaseConfiguration.create();
			// 设置连接参数：HBase数据库所在的主机IP
	        conf.set("hbase.zookeeper.quorum", "127.0.0.1");
	        // 设置连接参数：HBase数据库使用的端口
	        conf.set("hbase.zookeeper.property.clientPort", "2181");
	        // 取得一个数据库连接对象
	        if (conn==null||conn.isClosed()) {
	        	conn = ConnectionFactory.createConnection(conf);
	        }
		} catch (IOException e) {
			e.printStackTrace();
		}
		return conn;
	} 
}
